@extends('layouts.app')
@section('title', config('const.ab.ORDER_LIST'))

@section('content')
        <div class="col-lg-10 col-lg-offset-1">
            <div class="panel panel-default">
                <div class="panel-heading">
                    {{config('const.ab.ORDER_LIST')}}
                </div>
                <div class="panel-body">
                    @foreach($orders as $order)
                    <table class="table table-bordered order">
                        <thead>
                        <tr class="active">
                            <td colspan="6">
                                <div class="col-sm-8 text-left small">{{config('const.ab.SERIAL_NUMBER')}}：{{$order->no}}</div>
                                <div class="col-sm-4 text-right small">{{config('const.ab.CREATED_AT')}}：{{$order->created_at->format('Y-m-d H:i')}}</div>
                            </td>
                        </tr>
                        <tr>
                            <th class="col-sm-3">{{config('const.ab.GOODS')}}</th>
                            <th class="col-sm-2">{{config('const.ab.PRICE')}}</th>
                            <th class="col-sm-1">{{config('const.ab.AMOUNT')}}</th>
                            <th class="col-sm-2">{{config('const.ab.TOTAL_PRICE')}}</th>
                            <th class="col-sm-2">{{config('const.ab.STATUS')}}</th>
                            <th class="col-sm-2">{{config('const.ab.OPERATION')}}</th>
                        </tr>
                        </thead>
                        @foreach($order->items as $item)
                        <tr>
                            <td class="product-info">
                                <div>
                                    <a href="{{route('products.show', $item->product)}}">
                                        <img src="{{$item->product->image}}">
                                    </a>
                                </div>
                                <div>
                                    <span class="product-title">
                                        <a href="{{route('products.show', $item->product)}}">
                                            {{$item->product->title}}
                                        </a>
                                    </span>
                                    <span class="sku-title small">{{$item->productSku->title}}</span>
                                </div>
                            </td>
                            <td>
                                <em class="small">￥</em>{{$item->productSku->price}}
                            </td>
                            <td>
                                {{$item->amount}}
                            </td>
                            @if($loop->first)
                                <td rowspan="{{$count=count($order->items)}}">
                                    <em class="small">￥</em>{{$order->total_amount}}
                                </td>
                                <td rowspan="{{$count}}">
                                    @if($order->paid_at)
                                        @if($order->refund_status == 'REFUND_STATUS_PENDING')
                                            {{config('const.ab.PAID')}}
                                        @else
                                            {{config('const.ab.'.$order->refund_status)}}
                                        @endif
                                    @elseif($order->closed)
                                        {{config('const.at.CLOSED')}}
                                    @else
                                        {{config('const.ab.UNPAID')}}<br><br>
                                        {{config('const.ab.ORDER_CLOSED_AT')}}<br>
                                        {{$order->created_at->addSeconds(config('app.order_ttl'))->format('H:i')}}<br>
                                        <span class="small">
                                        {{config('const.ab.PLEASE_PAY_ORDER')}}
                                        </span>
                                    @endif
                                </td>
                                <td rowspan="{{$count}}">
                                    <a class="btn btn-primary btn-xs btn-detail" href="{{route('orders.show', $order)}}">
                                        {{config('const.ab.DETAIL')}}
                                    </a>
                                </td>
                            @endif
                        </tr>
                        @endforeach
                    </table>
                    @endforeach
                </div>
                <div class="panel-footer pull-right">
                    {{$orders->render()}}
                </div>
            </div>
        </div>
@endsection